package com.wmb.permissionservice.mapper;

import com.wmb.permissionservice.model.pojo.UserRole;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserPermissionMapper {

    /**
     * 通过 role_code 查询 role_id
     * @param user
     * @return
     */
    @Select("select role_id from roles where role_code = #{user}")
    Integer getRoleId(String user);

    /**
     * 绑定用户 对应的 角色
     * @param userRole
     * @return
     */
    @Insert("insert into user_roles (user_id, role_id) values (#{userId},#{roleId})")
    Integer insertUser(UserRole userRole);

    /**
     * 通过 user_id 查询 role_id
     * @param userId
     * @return
     */
    @Select("select role_id from user_roles where user_id = #{userId}")
    Integer getRoleIdByUserId(Long userId);

    /**
     * 修改用户角色权限-- superAdmin专用
     * @param userId
     * @param userRoleCodeNew
     */
    @Update("update user_roles set role_id = #{userRoleCodeNew} where user_id = #{userId} ")
    void updateUserRole(Long userId, String userRoleCodeNew);
}
